<template>
    <div>
        <div class="block">
            <el-tree
                :data="reset"
                show-checkbox
                node-key="id"
                default-expand-all
                :expand-on-click-node="false">
                <span class="custom-tree-node" slot-scope="{ node, data }" @mouseenter="mouseenter(node,data)" @mouseleave="mouseleave">
                    <input type="text" v-model="listData" v-show="showTree==node.id" @blur="lose(node,data)" @keyup.enter="submit(node,data)">
                    <span v-show="showTree!==node.id">{{ node.label }}</span>
                    <span v-show="showdelet==node.id">
                    <el-button
                        type="text"
                        size="mini"
                        @click="() => append(data)">
                        <i class="el-icon-plus" style="font-size:14px"></i>
                    </el-button>
                    <el-button
                        type="text"
                        size="mini"
                        @click="() => remove(node, data)">
                        <i class="el-icon-delete" style="font-size:14px"></i>
                    </el-button>
                    <el-button
                        type="text"
                        size="mini"
                        @click="() => edit(node, data)">
                        <i class="el-icon-edit" style="font-size:14px"></i>
                    </el-button>
                    </span>
                </span>
            </el-tree>
        </div>
    </div>
</template>

<script>

 let id = 1000;
export default {
    name:'roleTree',
    props:{
      reset:{
        type:Array,
        required:true
      }
    },
     data() {
      return {
        listData:'',    //input 输入框的值
        showTree:-1,   //点击单个显示input
        showdelet:-1,   //移入现实增删改
      }
    },

    methods: {
      append(data) {
        this.$emit('getClickData',data)
        this.$parent.dialogVisible=true
      },
      mouseenter(node,data){
        console.log(node)
          this.showdelet=node.id
      },
      mouseleave(){
          this.showdelet=-1
      },
      submit(node,data){
        if(this.listData==""){
          alert('编辑的数据不能为空')
        }else{
          this.$emit('compileData',data,this.listData)
          this.showTree=-1
        }
      },
      remove(node, data) {
        this.$emit('removeData',data)
      },
      lose(node,data){
          if(this.listData==""){
          alert('编辑的数据不能为空')
        }else{
          this.$emit('compileData',data,this.listData)
          this.showTree=-1
        }
      },
      edit(node,data){
          this.listData=node.label
          this.showTree=node.id
          console.log(node)
      },

      renderContent(h, { node, data, store }) {
        return (h('div',333))
          // <span class="custom-tree-node">
          //   <span>{node.label}</span>
          //   <span>
          //     <el-button size="mini" type="text" on-click={ () => this.append(data) }>Append</el-button>
          //     <el-button size="mini" type="text" on-click={ () => this.remove(node, data) }>Delete</el-button>
          //   </span>
          // </span>);
      }
    }
}
</script>

<style scoped lang="scss">

</style>
